<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/header.jsp"%>
<script type="text/javascript">
var gridManager;
var _dialog;
$(function (){
	PageLoader.initSearchPanel();
	gridManager = PageLoader.initGridPanel();
	
	var selectUrl="<%=contextPath %>/preprocess-PlaneInfo-listSourceSel.action";
	$.ajax({
			url: selectUrl,
			type: 'POST',
			dataType: 'json',
			error: function(){
				alert('渠道列表请求出错');
			},
			success: function(data){
				$('#attach_Hbase_Key').html('');
				$('#attach_Hbase_Key').append('<option value="">请选择渠道</option>' );
				$.each(data.listSource, function(idx, e){
					$('#attach_Hbase_Key').append('<option value='+e.hbaseKey+'>'+e.name+'</option>' );
				});
			}

		});
});

PageLoader = {
 //
 initSearchPanel:function(){
 //$("input[id^='executeTimeID_']").ligerDateEditor();//加载日期选择器
 },	
 initGridPanel:function(){
	 var g = $("#maingrid").ligerGrid({
         checkbox:true,
         height : '100%',
         rowHeight: 28,//行默认的高度
         headerRowHeight: 30,//表头行的高度
         pageSize : 20,
         onToNext:next,//条件查询方法
         columns: [
	         { display: '渠道', name: 'attachHbaseKey', width : 110, editor: { type: 'text' }},   
	         { display: '中文名称', name: 'grabChannel',width : 110,editor: { type: 'text' }},   
	         { display: '出发城市三字码', name: 'fromCity',width : 110,editor: { type: 'text' }},   
	         { display: '到达城市三字码', name: 'toCity',width : 110,editor: { type: 'text' }}, 
	         { display: '出发城市', name: 'fromCityName',width : 110,editor: { type: 'text' }}, 
	         { display: '到达城市', name: 'toCityName',width : 110,editor: { type: 'text' }}, 
	        { display: '是否国际', name: 'isInternational',width : 70,render: function (rowdata, rowindex, value){
	       	  return rowdata.isInternational==1 ? "是":"否";
	          }}, 
	          { display: '抓取往返', name: 'isReturn',width : 70,render: function (rowdata, rowindex, value){
	        	  return rowdata.isReturn==1 ? "是":"否";
	           }}, 
	           { display: '操作', name: 'id',render: function (rowdata, rowindex, value){
	         	 	 return "<a href='javascript:modifyAssignDay("+rowdata.id+")'>修改抓取规则</a>";
	            }},
	       ], 
        enabledEdit: false, clickToEdit: false,  
        parms : [
             	{name:"templateVO.attachHbaseKey",value: "请选择"},
 				{name:"templateVO.fromCity",value: $("#from_city").val()},
 				{name:"templateVO.toCity",value: $("#to_city").val()},
                 ],
        url:"<%=contextPath %>/airlinemanagement-TaskTemplateConfig-pageJson.action",
        width: '100%',
        toolbar: { items: [
            { id: "add", text: '增加', click: itemclick, icon: 'add' },
	        { line: true },
	        { id: "modify", text: '修改', click: itemclick, icon: 'modify' },
            { line: true }, 
	        { id: "remove", text: '删除', click: itemclick, icon: 'delete' }
        ]
        }
    });
	 //g.toggleCol("id",false);//隐藏id列
	 return g;
 }
}
//查询方法
function searchAction(){
     //form validate
   if(!Validator.Validate(document.getElementById("searchForm"),3))return;
//	var param=$("#searchForm").serialize();
	g = $("#maingrid").ligerGrid({
        checkbox:true,
        height : '100%',
        rowHeight: 28,//行默认的高度
        headerRowHeight: 30,//表头行的高度
        pageSize : 20,
        onToNext:next,//条件查询方法
        newPage:'1',
        columns: [
         { display: '渠道', name: 'attachHbaseKey', width : 110, editor: { type: 'text' }},   
         { display: '中文名称', name: 'grabChannel',width : 110,editor: { type: 'text' }},   
         { display: '出发城市三字码', name: 'fromCity',width : 110,editor: { type: 'text' }},   
         { display: '到达城市三字码', name: 'toCity',width : 110,editor: { type: 'text' }}, 
         { display: '出发城市', name: 'fromCityName',width : 110,editor: { type: 'text' }}, 
         { display: '到达城市', name: 'toCityName',width : 110,editor: { type: 'text' }}, 
        { display: '是否国际', name: 'isInternational',width : 70,render: function (rowdata, rowindex, value){
       	  return rowdata.isInternational==1 ? "是":"否";
          }}, 
          { display: '抓取往返', name: 'isReturn',width : 70,render: function (rowdata, rowindex, value){
        	  return rowdata.isReturn==1 ? "是":"否";
           }}, 
           { display: '操作', name: 'id',render: function (rowdata, rowindex, value){
         	 	 return "<a href='javascript:modifyAssignDay("+rowdata.id+")'>修改抓取规则</a>";
            }},
       ], 
      enabledEdit: false, clickToEdit: false,  
      parms : [
        	{name:"templateVO.attachHbaseKey",value: $("#attach_Hbase_Key").val()},
			{name:"templateVO.fromCity",value: $("#from_city").val()},
			{name:"templateVO.toCity",value: $("#to_city").val()},
               ],
      url:"<%=contextPath %>/airlinemanagement-TaskTemplateConfig-pageJson.action",
      width: '100%',
      toolbar: { items: [
          { id: "add", text: '增加', click: itemclick, icon: 'add' },
       { line: true },
       { id: "modify", text: '修改', click: itemclick, icon: 'modify' },
          { line: true }, 
       { id: "remove", text: '删除', click: itemclick, icon: 'delete' }
      ]
      }
   });
	//gridManager.loadServerData(param);/*执行服务器查询*/
}

/*分页条件查询参数*/
function next(){
	gridManager.setOptions({
        parms: [
	   {name:"templateVO.attachHbaseKey",value: $("#attach_Hbase_Key").val()},
		{name:"templateVO.fromCity",value: $("#from_city").val()},
		{name:"templateVO.toCity",value: $("#to_city").val()},
        ]
    });
}

function itemclick(item)
{
	switch (item.id) {
		case "add":
			openFormDialog(false);
	        break;
		case "modify":
			openFormDialog(true);
	        break;
		case "remove":
			deleteAction();
	        break;
	}
}


function openFormDialog(edit){
	var url = "airlinemanagement-TaskTemplateConfig-add.action";
	if(edit){
		var newRow = gridManager.getSelected();
	     if (!newRow) { alert('请选择行'); return; }
	     var i = 0;
	     $.each(gridManager.getCheckedRows(), function(index, element) {
			  i++;
		  });
	     if(i>1){
	    	 alert('请只选择一行'); return;
	     }
	     id = newRow.id;
	     url = "airlinemanagement-TaskTemplateConfig-update.action?id=" + newRow.id;
	}
	_dialog = jQuery.ligerDialog.open({
  	    title: edit ? '编辑' : '新增',
  	    url:url,
  	    isResize: true, width: 550, height: 550, isHidden: false
      });
}

//修改规则
function modifyAssignDay(id){
	var url = "airlinemanagement-TaskTemplateConfig-modifyAssignDay.action?id="+id;
	_dialog = jQuery.ligerDialog.open({
	    title: '编辑',
	    url:url,
	    isResize: true, width: 550, height: 550, isHidden: false
   });
}

/*删除行*/
function deleteAction()
{ 
    var newRow = gridManager.getSelected();
    if (!newRow) { alert('请选择行'); return; }
    
    var removeData = '';
	  $.each(gridManager.getCheckedRows(), function(index, element) {
		  removeData = removeData + element.id + ',';
	  });
	  removeData = removeData.substr(0, removeData.length - 1) ;
    var data = [{ name: 'ids', value: removeData }];
	 Koala.ajax({
 		async:true,
 		type : "POST",
 		url: "<%=contextPath %>/airlinemanagement-TaskTemplateConfig-delete.action",
 		data:data,
 		dataType:'json',
 		success: function(data, textStatus){
  			 gridManager.deleteSelectedRow();
  			 gridManager.loadData();
 		}
 		});
}

</script>
</head>
<body>
<div style="width:98%;height:100%;padding-left: 5px;">
<!-- search form -->
<form name="searchForm" id="searchForm" target="_self">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
<table width="800" border="0" style="margin:5px">
 <tr height="25px">
  <td width="16.6%">渠道:</td>
  <td width="16.7%">
    <select name="templateVO.attachHbaseKey"  id="attach_Hbase_Key" class="select-common">
	  <option value="">请选择</option>
	</select> 
  </td>
  <td width="16.6%">出发城市三字码:</td>
  <td width="16.7%">
    <input name="templateVO.fromCity" id="from_city" class="input-common"/> 
  </td>
  <td width="16.6%">到达城市三字码:</td>
  <td width="16.7%">
    <input name="templateVO.toCity" id="to_city" class="input-common"/> 
  </td>
  
 </tr>
</table>	
</td>
    <td><input id="searchButton" type="button" class="btn-normal" onclick="searchAction()" value="查询" /></td>
  </tr>
</table>	
</form>
<!-- grid -->
<div id="maingrid"></div> 
</div>
</body>
</html>
